<?php
defined('BME_INSERTION') or die('Error code: '.BME_INVALID_INSERT_ERROR);

if(empty($query)) $query="p1-25";

require_once(BME_ROOT."core/Sequence.php");
require_once(BME_ROOT."core/Dataset.php");
$Sqs=new BME_Sequence();
if(!is_array($QSqs)) $QSqs=$Sqs->getAll();
if(ereg("^p([0-9]+)-([0-9]+)$",$query,$reg)){
	$p=max((int)$reg[1],1);
	$n=(int)$reg[2];
	$nn=count($QSqs);
	$pp=ceil($nn/$n);
	$headers=array("%%query_id%%","%%query_source%%","%%query_sequences%%","%%query_seq_gen%%");
	foreach(array_slice($QSqs,$p*$n-$n,$n) as $id){
		$Sq=new BME_Sequence($id);
		$Ds=new BME_Dataset($Sq->getDataset());
		$content[$Sq->getId()]=array($Sq->getId(),$Sq->getSource(),
			"<div style='text-align:left;'>".$Sq->getDefline()."<br/>".
			"%%query_seq_fromds%%: ".$Ds->getName().", ".$Ds->getContact().
			"<div id='extra_data_".$Sq->getId()."' style='display:none;border:#777 1px solid;margin:5px;padding:5px'>&nbsp;".
			"</div></div>",
			$Sq->getGen());
	}
	if(!$_rq) $_rq="query/menu/sequences";
	$Dss=new BME_Dataset();
	$ds_opts="";
	foreach($Dss->getAll() as $dsid) {
		$Ds=new BME_Dataset($dsid);
		$ds_opts.= "<option value='filter_seqs_dataset:$dsid'>%%query_seq_dataset%% ".$Ds->getName().
			"</option>";
	}
	$header=<<<html
	<select style='background:white;color:black;' onchange='execAction("$_rq",this)'>
		<option value='' id='seq_actions_white' selected='selected'>%%query_actions%%</option>
		<option value='download'>%%query_seq_download_fasta%%</option>
	</select>
	<select style='background:white;color:black;' onchange='execAction("$_rq",this)'>
		<option value='' id='seq_display_white' selected='selected'>%%query_display%%</option>
		<option value='hide_extra'>%%query_seq_display_basic%%</option>
		<option value='show_best_blast'>%%query_seq_display_best_blast%%</option>
		<option value='show_all_blast'>%%query_seq_display_all_blast%%</option>
	</select>
	<select style='background:white;color:black;' onchange='execAction("$_rq",this)'>
		<option value='' id='seq_filter_white' selected='selected'>%%query_filter%%</option>
		$ds_opts
		<option value='show_all_sequences'>%%query_seq_showall%%</option>
	</select><br/><br/>
html;
}else echo "%%query_bad_request%%: $query<br/><br/>";


?>
